package cn.zhonghuanzhiyuan.sprc.basicinfo.controller;

import cn.org.bachelor.web.json.JsonResponse;

import cn.zhonghuanzhiyuan.sprc.basicinfo.domain.ThirdUnitEmployee;
import cn.zhonghuanzhiyuan.sprc.basicinfo.pojo.vo.*;
import cn.zhonghuanzhiyuan.sprc.basicinfo.service.ThirdUnitEmployeeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 第三方单位人员(ThirdUnitEmployee)控制层
 *
 * @author david
 * @since 2024-02-27 21:19:28
 */
@Api(tags = "第三方单位人员控制层")
@RestController
@RequestMapping("/thirdUnitEmployee")
@CrossOrigin // 线上不需要 （要注掉）
public class ThirdUnitEmployeeController {
    /**
     * 服务对象
     */
    @Autowired
    private ThirdUnitEmployeeService thirdUnitEmployeeService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @ApiOperation(value = "获取第三方单位人员单条数据")
    @GetMapping("/getThirdUnitEmployeeById/{id}")
    public HttpEntity<JsonResponse> getThirdUnitEmployeeById(@ApiParam(name = "id", value = "编号", required = true) @PathVariable String id) {
        ThirdUnitEmployee thirdUnitEmployee = thirdUnitEmployeeService.getThirdUnitEmployeeById(id);
        return JsonResponse.createHttpEntity(thirdUnitEmployee, HttpStatus.OK);
    }

    /**
     * 分页查询
     *
     * @param queryThirdUnitEmployeeVo
     * @return PageInfo<ThirdUnitEmployee>
     */
    @ApiOperation(value = "获取第三方单位人员分页数据")
    @PostMapping("/getThirdUnitEmployeePage")
    public HttpEntity<JsonResponse> getThirdUnitEmployeePage(@ApiParam(name = "queryThirdUnitEmployeeVo", value = "第三方单位人员", required = true) @RequestBody QueryThirdUnitEmployeeVo queryThirdUnitEmployeeVo) {
        PageHelper.startPage(queryThirdUnitEmployeeVo.getPageNum(), queryThirdUnitEmployeeVo.getPageSize());
        List<ThirdUnitEmployee> list = thirdUnitEmployeeService.selectThirdUnitEmployeeList(queryThirdUnitEmployeeVo);
        return JsonResponse.createHttpEntity(new PageInfo<>(list), HttpStatus.OK);
    }

    /**
     * 导出查询
     *
     * @param queryThirdUnitEmployeeVo
     * @return ThirdUnitEmployee
     */
    @ApiOperation(value = "获取第三方单位人员导出数据")
    @PostMapping("/getThirdUnitEmployeeList")
    public HttpEntity<JsonResponse> getThirdUnitEmployeeList(@ApiParam(name = "queryThirdUnitEmployeeVo", value = "第三方单位人员", required = true) @RequestBody QueryThirdUnitEmployeeVo queryThirdUnitEmployeeVo) {
        List<ThirdUnitEmployee> list = thirdUnitEmployeeService.selectThirdUnitEmployeeList(queryThirdUnitEmployeeVo);
        return JsonResponse.createHttpEntity(list, HttpStatus.OK);
    }

    /**
     * 新增或保存
     *
     * @param
     * @return
     */
    @ApiOperation(value = "修改或新增第三方单位人员")
    @PostMapping("/updateOrSaveThirdUnitEmployee")
    public HttpEntity<JsonResponse> updateOrSaveThirdUnitEmployee(@ApiParam(name = "updateOrSaveThirdUnitEmployeeVo", value = "第三方单位人员", required = true) @RequestBody UpdateOrSaveThirdUnitEmployeeVo updateOrSaveThirdUnitEmployeeVo) {
        thirdUnitEmployeeService.insertOrUpdate(updateOrSaveThirdUnitEmployeeVo);
        return JsonResponse.createHttpEntity(HttpStatus.OK);
    }


    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @ApiOperation(value = "批量删除第三方单位人员")
    @DeleteMapping("/deleteThirdUnitEmployeeByIds/{ids}")
    public HttpEntity<JsonResponse> deleteThirdUnitEmployeeByIds(@ApiParam(name = "idList", value = "主键集合", required = true) @PathVariable String ids) {
        thirdUnitEmployeeService.deleteByIds(ids);
        return JsonResponse.createHttpEntity(HttpStatus.OK);
    }

}
